package com.czz.portal.controller;

import com.czz.common.exception.ResultCodeEnum;
import com.czz.common.vo.R;
import com.czz.portal.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: LikeController
 * @Author Czz
 * @Date 2020/2/13
 * @Time 11:04
 **/
@RestController
@RequestMapping(value = "/like")
public class LikeController {

    @Autowired
    LikeService likeService;

    /**
     * @Description 用户咨询点赞/取消赞
     * @Param [userId, consultId]
     * @Return com.czz.common.vo.R
     * @Author Czz
     * @Date 2020/2/13
     * @Time 10:54
     **/
    @PostMapping(value = "/consult")
    public R consultLike(String userId, String consultId){
        if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(consultId)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        Boolean flag = likeService.consultLike(userId, consultId);
        if (flag) return R.ok().message("点赞成功！");
        else return R.ok().message("取消点赞成功！");
    }

    /**
    * @Description 问答回复点赞/取消赞
    * @Param [userId, commentId]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/15
    * @Time 9:58
    **/
    @PostMapping(value = "/comment")
    public R commentLike(String userId,String commentId){
        if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(commentId)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        Boolean flag = likeService.commentLike(userId,commentId);
        if (flag) return R.ok().message("点赞成功！");
        else return R.ok().message("取消点赞成功！");
    }

    /**
    * @Description 根据用户id查询用户评论点赞列表
    * @Param [id]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/3/25
    * @Time 11:52
    **/
    @GetMapping(value = "/comment/{id}")
    public R getUserCommentLike(@PathVariable String id){
        if (StringUtils.isEmpty(id)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        List<String> commentLikeList = likeService.getUserCommentLike(id);
        return R.ok().data("items",commentLikeList);
    }

    /**
    * @Description 根据用户id查询用户课程咨询点赞列表
    * @Param [id]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/3/25
    * @Time 17:31
    **/
    @GetMapping(value = "/consult/{id}")
    public R getUserConsultLike(@PathVariable String id){
        if (StringUtils.isEmpty(id)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        List<String> consultLikeList = likeService.getUserConsultLike(id);
        return R.ok().data("items",consultLikeList);
    }
}
